let table_name = "hot_city_table";
let table_data_url = "/sys/hot/city/list";
let number_list = "<'row'<'#mytool.col-xs-3'><'col-xs-9'>><'row'<'.col-xs-12'tr>><'row'<'#num_menu.col-xs-2'l><'col-xs-10'p>>";

function action_status() {
}

let dataManage = {
    currentItem: null,
    fuzzySearch: true,
    getQueryCondition: function (data) {
        let param = {};
        param.start = data.start;
        param.length = data.length;
        return JSON.stringify(param);
    },
};

let returnData = {
    getDate: [
        {
            className: "ellipsis",
            data: "",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "cityName",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "cityStatus",
            render: function (data, type, row, meta) {
                if (row.cityStatus === 0) {
                    return "下架";
                }else{
                    return "上架";
                }
            },
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "weight",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                let button = '';
                if (row.cityStatus === 0) {
                    button += '<button class="btn btn-sm btn-success" onclick=update_status(' + row.id + ',1)>上架</button>';
                }else{
                    button += '<button class="btn btn-sm btn-success" onclick=update_status(' + row.id + ',0)>下架</button>';
                }

                button += '<button class="btn btn-sm btn-success" onclick=hot_city_detail(' + row.id + ')>修改</button>';
                return button;
            }
        }
    ]
}

function foot_info(result) {
}

function createdRow(row, data, index) {
    if (data.role) {
        $(row).addClass("info");
    }
}

function drawCallback(settings) {
}

function search_user() {
    find();
}

function fn_draw_call_back() {
}

function create_hot_city() {
    $('#hot_city_modal').modal('show');
}

function update_status(id,status) {
    HttpUtils.post_json("/sys/hot/city/save", JSON.stringify({
        "id": id,
        "cityStatus": status
    }), function (result) {
        success_msg("更新成功", function (data) {
            find();
        });
    });
}

function hot_city_detail(id) {
    $('#banner_id').val(id);
    HttpUtils.post_json("/sys/hot/city/detail", JSON.stringify({"id": id}), function (result) {
        let data = result.data;
        $('#hot_city_id').val(data.id);
        $('#cityName').val(data.cityName);
        $('#cityStatus').val(data.cityStatus);
        $('#weight').val(data.weight);
        $('#hot_city_modal').modal('show');
    });
}

modalClose('hot_city_modal', function () {
    $('#hot_city_id').val('');
    $('#cityName').val('');
    $('#cityStatus').val('');
    $('#weight').val('');
});

function save_hot_city() {

    let id = $('#hot_city_id').val();

    let cityName = $('#cityName').val();

    let cityStatus = $('#cityStatus').val();

    let weight = $('#weight').val();

    HttpUtils.post_json('/sys/hot/city/save', JSON.stringify({
        "id": id,
        "cityName": cityName,
        "cityStatus": cityStatus,
        "weight":weight
    }), function (data) {
        $('#hot_city_modal').modal('hide');
        find();
    })
}